package com.qf.week3.day3.homework;

import java.util.*;

public class Win {
    public static void main(String[] args) {
        HashMap<Integer, String> map = new HashMap<>();
        
        map.put(2006,"意大利");
        map.put(2002,"巴西");
        map.put(1998,"法国");
        map.put(1998,"德国");
        map.put(1986,"阿根廷");
        map.put(1982,"意大利");
        map.put(1978,"阿根廷");
        map.put(1974,"德国");
        map.put(1970,"巴西");
        map.put(1966,"英格兰");
        map.put(1962,"巴西");
        map.put(1958,"巴西");
        map.put(1954,"德国");
        System.out.println(map);

       while(true){
           Scanner scanner = new Scanner(System.in);
           System.out.println("输入1或2  \t"+"1.输入年份查看当前年冠军 \t 2.查看该球队夺冠的年份列表 \t");
           int s = scanner.nextInt();
           switch (s){

               case 1:
                   System.out.println("请输入年份：");
                   int year = scanner.nextInt();
                   if(map.containsKey(year)){
                       System.out.println("这一年获得世界杯的是："+map.get(year));
                   }else{
                       System.out.println("该年没有举办世界杯!");
                   }
                   break;
               case 2:
                   System.out.println("输入一支球队的名字");
                   String teamName = scanner.next();
                   if(map.containsValue(teamName)){
                       List<Integer> keysForValue = Win.findKeysForValue(map, teamName);
                       System.out.println("这个对公获得世界杯的年份为："+keysForValue);


                   }else{
                       System.out.println("它没有获得过世界杯！");
                   }
                   break;


           }



       }
       }
    public static List<Integer> findKeysForValue(Map<Integer, String> map, String value) {
        List<Integer> keys = new ArrayList<>();
        for (Map.Entry<Integer, String> entry : map.entrySet()) {
            if (entry.getValue().equals(value)) {
                keys.add(entry.getKey());
            }
        }
        return keys;
    }

}
